Ext.ns("liang.mgr");

liang.mgr.CustomerPanel = Ext.extend(Ext.grid.GridPanel, {

               url : null,
               customerFormPanel : null,

               initComponent : function() {
                    var _store = new Ext.data.JsonStore({
                                   url : this.url,
                                   root : 'news',
                                   fields : ['id', 'title', 'context', 'time'],
                                   autoLoad : true
                              });
                    this.store = _store;

                    liang.mgr.CustomerPanel.superclass.initComponent.call(this);
               },
               constructor : function(cfg) {
                    cfg = cfg || {};
                    Ext.apply(this, cfg);
                    liang.mgr.CustomerPanel.superclass.constructor.call(this, {
                                   xtype : "grid",
                                   //title : "news",
                                   closable:true,
                                   width : 547,
                                   height : 250,
                                   columns : [{
                                                  header : "序号",
                                                  sortable : true,
                                                  dataIndex : "id",
                                                  width : 100
                                             }, {
                                                  header : "标题",
                                                  dataIndex : "title",
                                                  width : 100
                                             }, {
                                                  header : "内容",
                                                  dataIndex : "context",
                                                  width : 100
                                             }, {
                                                  header : "发表时间",
                                                  sortable : true,
                                                  dataIndex : "time",
                                                  width : 100
                                             }, {
                                                  header : "操作",
                                                  dataIndex : "",
                                                  width : 100,
                                                  align : "center"
                                             }],
                                   tbar : [{
                                                  scope : this,
                                                  text : "添加客户",
                                                  handler : this.addCustomer
                                             }]
                              });
               },
               addCustomer : function(btn, evt) {
                    var _addWin = new liang.mgr.CustomerWindow({
                         title:'新增客户',
                         msg : '添加成功',
                         newFormPanel: this.getCustomerFormPanel()
                    });
                    _addWin.show();
               },
               updateCustomer : function(btn, evt) {

               },
               deleteCustomer : function(btn, evt) {

               },
               getCustomerFormPanel : function() {

                    var _fieldSet = new Ext.form.FieldSet({
                                   title : '客户信息',
                                   anchor : "99%",
                                   items : [{
                                                  xtype : "textfield",
                                                  fieldLabel : "标题",
                                                  anchor : "100%"
                                                  ,name : 'title'
                                                  //,emptyText :'请输入客户标题'
                                                  ,allowBlank:false
                                                  ,blankText : '客户标题不能为空'
                                             }, {
                                                  xtype : "textarea",
                                                  fieldLabel : "内容",
                                                  height : 160,
                                                  anchor : "100%"
                                                  ,name : 'context'
                                                  ,allowBlank:false
                                                  //,emptyText :'请输入客户内容'
                                                  ,blankText : '客户内容不能为空'
                                             }]

                              });

                    var _formPanel = new Ext.form.FormPanel({
                                   style : 'padding: 10',
                                   title : "",
                                   labelWidth : 50,
                                   labelAlign : "left",
                                   buttonAlign : 'center',
                                   layout : "form",
                                   height : 250,
                                   baseCls : 'x-plain',
                                   items : _fieldSet
                              });

                    return _formPanel;
               }
          })

